home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility2 / resgauge.zip / CONFIG.C < prev    next >
C/C++ Source or Header  |  1992-08-23  |  10KB  |  332 lines

  1. // ============================================================================
  2. // config.c -- dialog procedure and support functions for the "Configure..."
  3. // dialog box.
  4. // ============================================================================
  5.  
  6.  
  7. #include <windows.h>
  8. #include <commdlg.h>
  9. #include "resgauge.h"
  10.  
  11.  
  12. // ============================================================================
  13. // > > > > > > > > > > > > > > >  code  begins  < < < < < < < < < < < < < < < <
  14. // ============================================================================
  15. // Processes messages for the "Configure..." dialog box.
  16. // ----------------------------------------------------------------------------
  17. BOOL
  18. CALLBACK
  19. ConfigDlgProc(
  20. HWND              hDlg,   // window handle of the dialog
  21. UINT              msg,    // message type
  22. WPARAM            wParam, // 16 bits of information
  23. LPARAM            lParam) // 32 additional bits of information
  24. {
  25.     static CONFIG Sconfig;
  26.  
  27.     BOOL          fReturn;
  28.  
  29.     fReturn = FALSE;
  30.     switch ( msg )
  31.     {
  32.         case WM_INITDIALOG:
  33.             // make a local copy of the global configuration data
  34.             Sconfig = GcfgCur;
  35.             // initialize the configuration dialog
  36.             InitConfigDlg(hDlg);
  37.             // tell DefDlgProc() that this message was handled
  38.             fReturn = TRUE;
  39.             break;
  40.  
  41.         // private message to reset the edit control
  42.         case WM_REVERT:
  43.             SetDlgItemInt(hDlg, IDD_PERCENT, GcfgCur.wThreshold, FALSE);
  44.             break;
  45.  
  46.         case WM_COMMAND:
  47.             fReturn = ConfigCommand(hDlg, &Sconfig, wParam, lParam);
  48.             break;
  49.     }
  50.  
  51.     return(fReturn);
  52. } // ConfigDlgProc
  53.  
  54.  
  55. // ----------------------------------------------------------------------------
  56. // Initializes the configuration dialog.
  57. // ----------------------------------------------------------------------------
  58. void
  59. FAR
  60. PASCAL
  61. InitConfigDlg(
  62. HWND      hDlg) // window handle of the dialog
  63. {
  64.     int   i;
  65.     HFONT hFont;
  66.     WORD  wTmp;
  67.  
  68.     // center the dialog
  69.     CenterDialog(hDlg);
  70.  
  71.     // set the font of the text boxes
  72.     hFont = GetStockObject(ANSI_VAR_FONT);
  73.     SendDlgItemMessage(hDlg, IDOK, WM_SETFONT, (WPARAM) hFont, FALSE);
  74.     SendDlgItemMessage(hDlg, IDCANCEL, WM_SETFONT, (WPARAM) hFont, FALSE);
  75.     for ( i = IDD_USER; i <= LAST_CONFIG; ++i )
  76.         SendDlgItemMessage(hDlg, i, WM_SETFONT, (WPARAM) hFont, FALSE);
  77.  
  78.     // set the "Monitor" radio buttons
  79.     if ( GcfgCur.wMonitor == MONITOR_GDI )
  80.         wTmp = IDD_GDI;
  81.     else if ( GcfgCur.wMonitor == MONITOR_USER )
  82.         wTmp = IDD_USER;
  83.     else
  84.         wTmp = IDD_BOTH;
  85.     CheckRadioButton(hDlg, IDD_USER, IDD_BOTH, wTmp);
  86.  
  87.     // set the "Alarm" radio buttons
  88.     if ( GcfgCur.wAlarmType == ALARM_FLASH )
  89.         wTmp = IDD_FLASH;
  90.     else
  91.         wTmp = IDD_BEEP;
  92.     CheckRadioButton(hDlg, IDD_BEEP, IDD_FLASH, wTmp);
  93.  
  94.     // load the edit control with the threshold value
  95.     SetDlgItemInt(hDlg, IDD_PERCENT, GcfgCur.wThreshold, FALSE);
  96.  
  97.     // limit the edit control to 2 characters
  98.     SendDlgItemMessage(hDlg, IDD_PERCENT, EM_LIMITTEXT, 2, 0L);
  99.  
  100.     // enable or disable the alarm controls
  101.     EnableAlarmControls(hDlg, GcfgCur.fAlarmEnabled);
  102. } // InitConfigDlg
  103.  
  104.  
  105. // ----------------------------------------------------------------------------
  106. // Handles WM_COMMAND messages to the configuration dialog.
  107. // ----------------------------------------------------------------------------
  108. BOOL
  109. FAR
  110. PASCAL
  111. ConfigCommand(
  112. HWND            hDlg,    // window handle of the dialog
  113. PCONFIG         pConfig, // configuration structure in caller
  114. WPARAM          wParam,  // 16 bits of information
  115. LPARAM          lParam)  // 32 additional bits of information
  116. {
  117.     BOOL        fEnable;
  118.     BOOL        fNoError;
  119.     BOOL        fReturn;
  120.     DWORD FAR * lpdwTmp;
  121.     WORD        wTmp;
  122.  
  123.     fReturn = FALSE;
  124.     switch ( wParam )
  125.     {
  126.         // monitor the GDI heap
  127.         case IDD_GDI:
  128.             CheckRadioButton(hDlg, IDD_USER, IDD_BOTH, wParam);
  129.             GwFree = 0;
  130.             GcfgCur.wMonitor = MONITOR_GDI;
  131.             break;
  132.  
  133.         // monitor the USER heap
  134.         case IDD_USER:
  135.             CheckRadioButton(hDlg, IDD_USER, IDD_BOTH, wParam);
  136.             GwFree = 0;
  137.             GcfgCur.wMonitor = MONITOR_USER;
  138.             break;
  139.  
  140.         // monitor both heaps
  141.         case IDD_BOTH:
  142.             CheckRadioButton(hDlg, IDD_USER, IDD_BOTH, wParam);
  143.             GwFree = 0;
  144.             GcfgCur.wMonitor = MONITOR_BOTH;
  145.             break;
  146.  
  147.         // edit the gauge color
  148.         case IDD_GAUGE_COLOR:
  149.             if ( GcfgCur.wMonitor == MONITOR_GDI )
  150.                 lpdwTmp = &(GcfgCur.dwColorGDI);
  151.             else if ( GcfgCur.wMonitor == MONITOR_USER )
  152.                 lpdwTmp = &(GcfgCur.dwColorUser);
  153.             else
  154.                 lpdwTmp = &(GcfgCur.dwColorBoth);
  155.             if ( DoColor(hDlg, lpdwTmp) )
  156.                 GwFree = 0;
  157.             break;
  158.  
  159.         // toggle the alarm
  160.         case IDD_ENABLE:
  161.             fEnable = LOWORD(SendDlgItemMessage(hDlg,
  162.                                                 wParam,
  163.                                                 BM_GETCHECK,
  164.                                                 0,
  165.                                                 0L));
  166.             GcfgCur.fAlarmEnabled = !fEnable;
  167.             EnableAlarmControls(hDlg, GcfgCur.fAlarmEnabled);
  168.             break;
  169.  
  170.         // beep for an alarm
  171.         case IDD_BEEP:
  172.             CheckRadioButton(hDlg, IDD_BEEP, IDD_FLASH, wParam);
  173.             GcfgCur.wAlarmType = ALARM_BEEP;
  174.             break;
  175.  
  176.         // flash for an alarm
  177.         case IDD_FLASH:
  178.             CheckRadioButton(hDlg, IDD_BEEP, IDD_FLASH, wParam);
  179.             GcfgCur.wAlarmType = ALARM_FLASH;
  180.             break;
  181.  
  182.         // decrement the threshold value
  183.         case IDD_MINUS:
  184.             wTmp = GetDlgItemInt(hDlg, IDD_PERCENT, NULL, FALSE);
  185.             if ( wTmp > 1 )
  186.             {
  187.                 --wTmp;
  188.                 SetDlgItemInt(hDlg, IDD_PERCENT, wTmp, FALSE);
  189.                 GcfgCur.wThreshold = wTmp;
  190.             }
  191.             else
  192.             {
  193.                 MessageBeep(0);
  194.             }
  195.             break;
  196.  
  197.         // check the value entered in the edit control
  198.         case IDD_PERCENT:
  199.             if ( HIWORD(lParam) == EN_CHANGE )
  200.             {
  201.                 wTmp = GetDlgItemInt(hDlg,
  202.                                      IDD_PERCENT,
  203.                                      (BOOL FAR *) &fNoError,
  204.                                      FALSE);
  205.                 if ( fNoError )
  206.                 {
  207.                     GcfgCur.wThreshold = wTmp;
  208.                 }
  209.                 else
  210.                 {
  211.                     MessageBeep(0);
  212.                     PostMessage(hDlg, WM_REVERT, 0, 0L);
  213.                 }
  214.             }
  215.             break;
  216.  
  217.         // increment the threshold value
  218.         case IDD_PLUS:
  219.             wTmp = GetDlgItemInt(hDlg, IDD_PERCENT, NULL, FALSE);
  220.             if ( wTmp < 99 )
  221.             {
  222.                 ++wTmp;
  223.                 SetDlgItemInt(hDlg, IDD_PERCENT, wTmp, FALSE);
  224.                 GcfgCur.wThreshold = wTmp;
  225.             }
  226.             else
  227.             {
  228.                 MessageBeep(0);
  229.             }
  230.             break;
  231.  
  232.         // save and use the current configuration
  233.         case IDOK:
  234.             SaveConfig();
  235.             EndDialog(hDlg, TRUE);
  236.             fReturn = TRUE;
  237.             break;
  238.  
  239.         // use the current configuration
  240.         case IDD_APPLY:
  241.             EndDialog(hDlg, TRUE);
  242.             fReturn = TRUE;
  243.             break;
  244.  
  245.         // reset the current configuration to default values
  246.         case IDD_DEFAULT:
  247.             GcfgCur = GcfgDef;
  248.             GwFree = 0;
  249.             InitConfigDlg(hDlg);
  250.             break;
  251.  
  252.         // restore the original configuration
  253.         case IDCANCEL:
  254.             GcfgCur = *pConfig;
  255.             GwFree = 0;
  256.             EndDialog(hDlg, FALSE);
  257.             fReturn = TRUE;
  258.             break;
  259.     }
  260.  
  261.     return(fReturn);
  262. } // ConfigCommand
  263.  
  264.  
  265. // ----------------------------------------------------------------------------
  266. // Enables or disables all the alarm controls.
  267. // ----------------------------------------------------------------------------
  268. void
  269. FAR
  270. PASCAL
  271. EnableAlarmControls(
  272. HWND    hDlg,    // window handle of the dialog
  273. BOOL    fEnable) // TRUE if the controls are to be enabled
  274. {
  275.     int i;
  276.  
  277.     SendDlgItemMessage(hDlg, IDD_ENABLE, BM_SETCHECK, fEnable, 0L);
  278.     for ( i = IDD_BEEP; i <= IDD_THRESHOLD; ++i )
  279.         EnableWindow(GetDlgItem(hDlg, i), fEnable);
  280.     for ( i = IDD_MINUS; i <= IDD_PLUS; ++i )
  281.         EnableWindow(GetDlgItem(hDlg, i), fEnable);
  282. } // EnableAlarmControls
  283.  
  284.  
  285. // ----------------------------------------------------------------------------
  286. // Wrapper for the common color selection dialog.
  287. // ----------------------------------------------------------------------------
  288. BOOL
  289. FAR
  290. PASCAL
  291. DoColor(
  292. HWND            hWnd,      // window handle
  293. DWORD FAR *     lpdwColor) // color to be modified
  294. {
  295.     int         i;
  296.     BOOL        fReturn;
  297.     CHOOSECOLOR cc;
  298.     COLORREF    aclrCust[16];
  299.  
  300.     // assume failure
  301.     fReturn = FALSE;
  302.  
  303.     // set the custom color controls to white
  304.     for ( i = 0; i < 16; ++i )
  305.         aclrCust[i] = RGB(255, 255, 255);
  306.  
  307.     // initialize the structure members
  308.     cc.lStructSize    = sizeof(CHOOSECOLOR);
  309.     cc.hwndOwner      = hWnd;
  310.     cc.hInstance      = NULL;
  311.     cc.rgbResult      = *lpdwColor;
  312.     cc.lpCustColors   = aclrCust;
  313.     cc.Flags          = CC_RGBINIT | CC_PREVENTFULLOPEN;
  314.     cc.lCustData      = 0;
  315.     cc.lpfnHook       = NULL;
  316.     cc.lpTemplateName = NULL;
  317.  
  318.     // call the common color selection dialog
  319.     if ( ChooseColor(&cc) )
  320.     {
  321.         *lpdwColor = cc.rgbResult;
  322.         fReturn = TRUE;
  323.     }
  324.  
  325.     return(fReturn);
  326. } // DoColor
  327.  
  328.  
  329. // ===============
  330. // end of config.c
  331. // ===============
  332.